package com.bw.hxc.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bw.hxc.entity.Coop;
import com.bw.hxc.entity.Search;
import com.bw.hxc.service.ICoopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 黄旭超
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/coop")
public class CoopController {

    @Autowired
    ICoopService coopService;

    @RequestMapping("list")
    public Page<Coop> list(@RequestBody Search search){
        Page<Coop> coopPage = new Page<>(search.getPage(), search.getPageSize());
        QueryWrapper<Coop> coopQueryWrapper = new QueryWrapper<>();
        if (StringUtils.hasText(search.getKey())){
            coopQueryWrapper.like("name",search.getKey());
        }
        if (search.getArea()!=0){
            coopQueryWrapper.eq("area",search.getArea());
        }
        if (search.getStartDate()!=null){
            coopQueryWrapper.ge("startDate",search.getStartDate());
        }
        if (search.getEndDate()!=null){
            coopQueryWrapper.le("startDate",search.getEndDate());
        }
        Page<Coop> page = coopService.page(coopPage, coopQueryWrapper);
        return page;
    }
}
